package com.hzyb.shopCart.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.hzyb.shopCart.service.ShopCartService;

@RestController
@RequestMapping("/shopCart")
public class ShopCartController {


	private static final Logger LOGGER = LoggerFactory.getLogger(ShopCartController.class);

	@Autowired
	private ShopCartService ShopCartService;

	@RequestMapping("/addShopCart")
	public Map<String, Object> addShopCart(@RequestParam String shopCart){
		Map<String, Object> map=new HashMap<>();
		map.put("status", "fail");
		try {
			JSONObject jsonObject=JSONObject.parseObject(shopCart);
			map=ShopCartService.addShopCart(jsonObject);
		} catch (Exception e) {
			LOGGER.error(e.toString());
		}
		return map;
	}
	
	@RequestMapping("/numChange")
	public Map<String, Object> numChange(@RequestParam String num,@RequestParam String cartId){
		Map<String, Object> map=new HashMap<>();
		map.put("status", "fail");
		try {
			ShopCartService.numChange(cartId, num);
			map.put("status", "fail");
		} catch (Exception e) {
			LOGGER.error(e.toString());
		}
		return map;
	}
}
